/*
 * 创建组件的整体的css文件
 * */
import { resolve } from "path";
import { FsFile } from "./utils/FsFile.js";
import { createPackageJson } from "./templates/json.js";
import { log } from "./utils/utils.js";
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { LIB_NAME } from "../build/buildLib.js";

const __filename = fileURLToPath(import.meta.url);
const __dirname = resolve(dirname(__filename), `../${LIB_NAME}/dist/styles`);

// 文件根目录
const FILE_ROOT_PATH = __dirname;

// 创建文件对象
const fsFile = new FsFile(FILE_ROOT_PATH);

export async function createAllCssFile() {
  // 创建的css文件路径
  const allCssPath = resolve(FILE_ROOT_PATH, "./index.css");
  const folderNames = await fsFile.getFolderNames();
  if (!folderNames) return;
  folderNames.forEach(folder => {
    const filePath = fsFile.join(folder, `${folder}.css`);
    let fileContent = fsFile.getFileContent(filePath);
    fileContent = fileContent.replaceAll("../../assets", "./assets");
    // 创建文件并写入内容
    fsFile.appendFile(allCssPath, fileContent);
  });
  log.success(`成功生成所有组件的css文件`);
}

await createAllCssFile();
